<template>
  <div>
    <svg-icon icon-class="isFullscreen ? 'exit-fullscreen' : 'fullscreen'" class="fullscreen" @click="toggleFull" />
  </div>
</template>
<script>
import screenfull from 'screenfull'
export default {
  name: 'Screenfull',
  data() {
    return {
      isFullscreen: false // 是否全屏
    }
  },

  mounted() {
    // change 监听全屏与否的状态
    screenfull.on('change', () => {
      // screenfull.isFullscreen 是插件本身给提供的全屏与否的状态
      // 如果是全屏，值为 true，如果退出全屏，值为 false
      // console.log(screenfull.isFullscreen)
      this.isFullscreen = screenfull.isFullscreen
    })
  },
  methods: {
    toggleFull() {
      // toggle 方法是 screenfull 提供的切换到全屏的方法
      screenfull.toggle()
      this.isFullscreen = !this.isFullscreen
    }
  }
}
</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  color: #fff;
  cursor: pointer;
}
</style>
